var $table = $("#storageTab");
$(function () {
	//初始化表格
    initTable();
    //条件查询
    $("#querystorageBtn").click(function () {
        $table.bootstrapTable('refresh');
    });
    //增加按钮
    $("#addBut").click(function () {
    	initstorageEdit(null);
    });
});

function initTable() {
    $table.bootstrapTable({
        dataType: "json",
        pagination: true, //分页
        striped: true,
        cache: false,	//是否使用缓存，默认是true
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        method: "post",	//使用post提交
        queryParams: queryParams,
        url: '../storage/getStorageInfoByPage.htm',
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
			{
				title: "序号",
			    align: 'center',
			    formatter:function(value,row,index){
			    	return index + 1;
			    }
			},
            {
                title: "仓库编号",
                field: "storageNum",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "仓库大小",
                field: "storageSize",
                align: 'center',
                valign: 'middle'

            },
            {
                title: "仓库名",
                field: "storageName",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "仓储类型",
                field: "storageType",
                align: 'center',
                formatter: function(value, row, index){
                    var storageType = "";
                    if(row.storageType == 1){
                        storageType = '普通';
                    }else if(row.storageType == 2){
                        storageType ='冷链';
                    }
                    return storageType;
                }
            },
            {
                title: "仓库地址",
                field: "storageAddr",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "仓储状态",
                field: "storageState",
                align: 'center',
                formatter: function(value, row, index){
                    var storageState = "";
                    if(row.storageState == 1){
                        storageState = '满仓';
                    }else if(row.storageState == 2){
                        storageState = '正常';
                    }else if(row.storageState == 3){
                        storageState = '空仓';
                    }
                    return storageState;
                }
            },
            {
                title: "插入时间",
                field: "storageInsTime",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "是否删除",
                field: "storageIsDelete",
                align: 'center',
                formatter: function(value, row, index){
                    var storageIsDelete = "";
                    if(row.storageIsDelete == 0){
                        storageIsDelete = '未删除';
                    }else if(row.storageIsDelete == 1){
                        storageIsDelete = '已删除';
                    }
                    return storageIsDelete;
                }
            },
            {
                title: "操作",
                align: 'center',
                formatter: function (value, row, index) {
                    var e = '<button class="btn btn-sm btn-info" type="button" onclick="initstorageEdit(\'' + row.storageId + '\')"><i class="fa fa-edit"></i> 编辑</button> ';
                    return e;
                }
            }
        ]
    });
}

//分页参数，条件查询时的参数
function queryParams(queryParamsType){
	var temp = {
		limit: queryParamsType.limit,   //页面大小
		offset: queryParamsType.offset,  //页码
		storageName: $.trim($('#storageName').val()),
	};
	return temp;
}

//编辑公司信息
function initstorageEdit(id){
    var title;
    if(id){
        title = '编辑仓库';
    }else{
        title = '新增仓库';
    }
    layer.open({
        type: 2,
        title: title,
        maxmin: true,
        shadeClose: false, //点击遮罩关闭层
        area : ['500px' , '650px'],
        content: '../storage/edit_storage.htm?id='+id,
        success: function(layero, index){
        }
    });
}

